/**
 * <copyright>
 * </copyright>
 *

 */
package net.maylander.bfcpublog.bfwb.brainfuckLanguage.impl;

import java.util.Collection;

import net.maylander.bfcpublog.bfwb.brainfuckLanguage.BfValue;
import net.maylander.bfcpublog.bfwb.brainfuckLanguage.BrainfuckLanguagePackage;
import net.maylander.bfcpublog.bfwb.brainfuckLanguage.MacroCall;
import net.maylander.bfcpublog.bfwb.brainfuckLanguage.MacroDef;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Macro Call</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link net.maylander.bfcpublog.bfwb.brainfuckLanguage.impl.MacroCallImpl#getMacro <em>Macro</em>}</li>
 *   <li>{@link net.maylander.bfcpublog.bfwb.brainfuckLanguage.impl.MacroCallImpl#getActuals <em>Actuals</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MacroCallImpl extends AbstractStmtImpl implements MacroCall
{
  /**
   * The cached value of the '{@link #getMacro() <em>Macro</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMacro()
   * @generated
   * @ordered
   */
  protected MacroDef macro;

  /**
   * The cached value of the '{@link #getActuals() <em>Actuals</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getActuals()
   * @generated
   * @ordered
   */
  protected EList<BfValue> actuals;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected MacroCallImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return BrainfuckLanguagePackage.Literals.MACRO_CALL;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public MacroDef getMacro()
  {
    if (macro != null && macro.eIsProxy())
    {
      InternalEObject oldMacro = (InternalEObject)macro;
      macro = (MacroDef)eResolveProxy(oldMacro);
      if (macro != oldMacro)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, BrainfuckLanguagePackage.MACRO_CALL__MACRO, oldMacro, macro));
      }
    }
    return macro;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public MacroDef basicGetMacro()
  {
    return macro;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMacro(MacroDef newMacro)
  {
    MacroDef oldMacro = macro;
    macro = newMacro;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BrainfuckLanguagePackage.MACRO_CALL__MACRO, oldMacro, macro));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<BfValue> getActuals()
  {
    if (actuals == null)
    {
      actuals = new EObjectContainmentEList<BfValue>(BfValue.class, this, BrainfuckLanguagePackage.MACRO_CALL__ACTUALS);
    }
    return actuals;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case BrainfuckLanguagePackage.MACRO_CALL__ACTUALS:
        return ((InternalEList<?>)getActuals()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case BrainfuckLanguagePackage.MACRO_CALL__MACRO:
        if (resolve) return getMacro();
        return basicGetMacro();
      case BrainfuckLanguagePackage.MACRO_CALL__ACTUALS:
        return getActuals();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case BrainfuckLanguagePackage.MACRO_CALL__MACRO:
        setMacro((MacroDef)newValue);
        return;
      case BrainfuckLanguagePackage.MACRO_CALL__ACTUALS:
        getActuals().clear();
        getActuals().addAll((Collection<? extends BfValue>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case BrainfuckLanguagePackage.MACRO_CALL__MACRO:
        setMacro((MacroDef)null);
        return;
      case BrainfuckLanguagePackage.MACRO_CALL__ACTUALS:
        getActuals().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case BrainfuckLanguagePackage.MACRO_CALL__MACRO:
        return macro != null;
      case BrainfuckLanguagePackage.MACRO_CALL__ACTUALS:
        return actuals != null && !actuals.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //MacroCallImpl
